home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Atari Mega Archive 1
/
Atari Mega Archive - Volume 1.iso
/
cli
/
mx2src.arc
/
NETWORK.MOD
< prev
next >
Wrap
Text File
|
1989-01-05
|
28KB
|
853 lines
(* Copyright 1987 fred brooks LogicTek *)
(* *)
(* *)
(* First Release 12/8/87-FGB *)
(* *)
IMPLEMENTATION MODULE NETWORK ;
(* --------------------------------------------------------------------------
NETWORK : MIDI PORT TWO CPU NETWORK FOR TDI Modula-2/ST
--------------------------------------------------------------------------*)
(*$T-,$S-,$A+ *)
FROM SYSTEM IMPORT ADDRESS, ADR, SETREG, CODE, REGISTER ,BYTE ,TSIZE;
FROM BIOS IMPORT BPB ,BConStat ,BConIn, BCosStat, BConOut, Device,
MediaChange,MCState,GetBPB,RWAbs,RW,DriveSet,DriveMap;
FROM XBIOS IMPORT SuperExec,IORec,IORECPTR,IOREC,SerialDevice;
FROM GEMDOS IMPORT TermRes,Open,Close ;
IMPORT GEMDOS;
FROM ASCII IMPORT SYN,STX,SOH,BEL;
CONST
MaxSeq = 1;
recsize = 511;
USER = 324159265;
retry = 10;
debug = FALSE;
trace = FALSE;
(* Because we dont know what registers the BIOS is using we must use
the following opcodes to save the registers *)
MOVEMDEC = 48E7H ; (* 68000 opcode for MOVEM <regs>,-(A7) *)
MOVEMINC = 4CDFH ; (* 68000 opcode for MOVEM (A7)+,<regs> *)
SAVEREGS = 07FFCH ; (* Registers D1..A5 for DEC *)
RESTREGS = 03FFEH ; (* Registers D1..A5 for INC *)
RTS = 04E75H ; (* 68000 return from subroutine opcode *)
TYPE
(* Procedure types to mimic correct sequence for "C" BIOS routines *)
CBPBProc = PROCEDURE ( CARDINAL ) ;
CMediaChProc = PROCEDURE ( CARDINAL ) ;
CRWAbsProc = PROCEDURE ( CARDINAL, CARDINAL, CARDINAL, ADDRESS, CARDINAL );
MIDIbuffer = ARRAY [0..512] OF CARDINAL;
SequenceNr = [0..MaxSeq];
message = ARRAY [0..recsize] OF BYTE;
message1 = ARRAY [0..17] OF BYTE;
FrameKind = (ack,data,callreq,callaccp,clearreq,clearconf,
resetreq,resetconf,diag);
DataKind = (rdmediareq,rdmediaconf,rdbpbreq,rdbpbconf,
rdrwabsreq,rdrwabsconf);
evtype = (framearrival,cksumerr,timeout,hostready,reset,nothing);
frame = RECORD
syn : CHAR; (* these are sync chars *)
stx : CHAR; (* for the frames *)
kind : FrameKind;
seq : SequenceNr;
ack : SequenceNr;
cmd : DataKind;
rw : CARDINAL; (* read or write data *)
recno : CARDINAL; (* sector for data*)
d0 : LONGCARD; (* data return variable *)
info : message;
user : LONGCARD;
cksum : CARDINAL;
END;
framecptr = POINTER TO framecmd;
framecmd = RECORD
syn : CHAR; (* these are sync chars *)
stx : CHAR; (* for the frames *)
kind : FrameKind;
seq : SequenceNr;
ack : SequenceNr;
cmd : DataKind;
rw : CARDINAL; (* read or write data *)
recno : CARDINAL; (* sector for data*)
d0 : LONGCARD; (* data return variable *)
info : message1;
user : LONGCARD;
cksum : CARDINAL;
END;
control = RECORD
magic : LONGCARD;
reset : BOOLEAN;
networkactive : BOOLEAN;
remotedrive : CARDINAL;
drivemap : DriveSet;
nextframetosend : SequenceNr;
frameexpected : SequenceNr;
sendreset : BOOLEAN;
END;
consave = RECORD
magic : LONGCARD;
reset : BOOLEAN;
networkactive : BOOLEAN;
END;
frameptr = POINTER TO ARRAY [0..1024] OF BYTE;
VAR
(* BIOS variables : These can only be accessed with the 68000 in supervisor
mode. The Modula-2 language allows you to fix the location of variables *)
HDBPB [0472H] : ADDRESS ; (* hard disk get Bios Parameter Block *)
HDRWAbs [0476H] : ADDRESS ; (* hard disk read/write abs *)
HDMediaCh [047EH] : ADDRESS ; (* hard disk media change *)
DriveBits [04C2H] : SET OF [0..31]; (* disk drives present map *)
flock [043EH] : LONGCARD; (* disk access in progress *)
hz200 [04baH] : LONGCARD; (* 200hz clock counter *)
clock : LONGCARD;
Dptr : DriveSet; (* save original drive map *)
Mptr : LONGCARD;
charcount,j,framesize,cksum,recframesize,sndframesize,
SIZEframe,SIZEframecmd : CARDINAL;
networkconnect : BOOLEAN; (* DCD = 1 TRUE *)
gotframe : BOOLEAN;
framebufferfull : BOOLEAN;
cleartosend : BOOLEAN;
readytosend : BOOLEAN;
requesttosend : BOOLEAN;
framewaiting : BOOLEAN;
timer,OK,installed : BOOLEAN;
gotmediach : ARRAY [0..5] OF BOOLEAN;
gotbpb : ARRAY [0..5] OF BOOLEAN;
networkerror : BOOLEAN;
shortframe : BOOLEAN;
sendlong : BOOLEAN;
sframe,rframe,SFRAME,RFRAME,
nframe1,nframe2 : frame;
rframeptr,sframeptr,
bpbptr,nbpbptr : frameptr;
framecmdptr,framecmdptr1 : framecptr;
event : evtype;
C : control;
recchar,timestart,timefortimeout,timeouttime : LONGCARD;
timestart1,timefortimeout1,timeouttime1 : LONGCARD;
result,r,i,i1,i2,i3,mediacount,handle : INTEGER;
D0ptr : POINTER TO LONGCARD;
wsector,drvnr,DriveA,DriveF,devicestart,d,R : CARDINAL;
rbuffer : MIDIbuffer;
rbptr : IORECPTR;
numBytes,sec,min,hour,time,count : LONGCARD ;
status : LONGINT ;
(* The following are saved copies of the BIOS variables so that the real
hard disk routines can be called if a hard disk access is requested. *)
SaveHDBPB : CBPBProc ; (* hard disk get Bios Parameter Block *)
SaveHDRWAbs : CRWAbsProc ; (* hard disk read/write abs *)
SaveHDMediaCh : CMediaChProc ; (* hard disk media change *)
(* NETWORK control *)
NetworkBPB : ARRAY [0..5] OF BPB ; (* BIOS Parameter block for NETWORK *)
PROCEDURE MoveMemory ( From, To : ADDRESS ; Bytes : LONGCARD ) ;
(* This routine shows how time critical portions of code can be optimised to
run faster. It relys on the code generation rules of the compiler which
can be checked by dis-assembling the link file with DecLnk.*)
CONST
MOVEB = 12D8H ; (* MOVE.B (A0)+,(A1)+ *)
MOVEL = 22D8H ; (* MOVE.L (A0)+,(A1)+ *)
A0 = 0+8 ; (* register A0 *)
A1 = 1+8 ; (* register A1 *)
BEGIN
SETREG(A0,From) ; (* load From pointer into A0 *)
SETREG(A1,To) ; (* load To pointer into A1 *)
IF ( ODD(From) OR ODD(To) ) THEN (* must do bytes *)
WHILE ( Bytes <> 0 ) DO
CODE(MOVEB) ;
DEC(Bytes) ;
END ;
ELSE (* even addresses so can do long moves *)
WHILE ( Bytes > 3 ) DO
CODE(MOVEL) ;
DEC(Bytes,4) ;
END ;
WHILE ( Bytes <> 0 ) DO
CODE(MOVEB) ; (* clean up remainder *)
DEC(Bytes) ;
END ;
END ;
END MoveMemory ;
PROCEDURE inc(VAR k: SequenceNr); (* increment k circular